package com.jinloes.webfit;

import com.jinloes.webfit.persistence.User;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

public class HibernateHSQLUtils {
	static {
		AnnotationConfiguration config = new AnnotationConfiguration().
        setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect").
        setProperty("hibernate.connection.driver_class", "org.hsqldb.jdbcDriver").
        setProperty("hibernate.connection.url", "jdbc:hsqldb:mem:modules").
        setProperty("hibernate.connection.username", "sa").
        setProperty("hibernate.connection.password", "").
        setProperty("hibernate.connection.pool_size", "1").
        setProperty("hibernate.connection.autocommit", "true").
        setProperty("hibernate.cache.provider_class", "org.hibernate.cache.HashtableCacheProvider").
        setProperty("hibernate.hbm2ddl.auto", "create-drop").
        setProperty("hibernate.show_sql", "true").
        setProperty("hibernate.format_sql","true").
        setProperty("hibernate.use_sql_comments","true").
        setProperty("hibernate.generate_statistics","true").
        addAnnotatedClass(User.class);

		factory = (config.buildSessionFactory());

	}

    final private static SessionFactory factory;

    public static SessionFactory getSessionFactory() {
    	return factory;
    }

    public static synchronized Session getSession() {
        return factory.openSession();
    }
}
